import { http } from "@/utils/http";

export type ChargeTypeItem = {
  id: number;
  name: string;
  remarks: string;
  createTime?: string;
  updateTime?: string;
  tenantId?: number;
};

export type ChargeTypeListParams = {
  page: number;
  limit: number;
  name: string;
};

export type ChargeTypeListResult = {
  code: number;
  data: {
    total: number;
    list: ChargeTypeItem[];
    pageNum: number;
    pageSize: number;
    size: number;
    startRow: number;
    endRow: number;
    pages: number;
    prePage: number;
    nextPage: number;
    isFirstPage: boolean;
    isLastPage: boolean;
    hasPreviousPage: boolean;
    hasNextPage: boolean;
    navigatePages: number;
    navigatepageNums: number[];
    navigateFirstPage: number;
    navigateLastPage: number;
  };
  message: string;
};

export type ChargeTypeAddParams = {
  name: string;
  remarks: string;
};

export type ChargeTypeUpdateParams = {
  id: number;
  name: string;
  remarks: string;
};

export type ChargeTypeDeleteParams = {
  id: number;
};

// 获取收费项目类别列表
export const getChargeTypeList = (params: ChargeTypeListParams) => {
  return http.request<ChargeTypeListResult>("post", "/spChargeType/list", {
    data: params
  });
};

// 新增收费项目类别
export const addChargeType = (params: ChargeTypeAddParams) => {
  return http.request("post", "/spChargeType/add", { data: params });
};

// 更新收费项目类别
export const updateChargeType = (params: ChargeTypeUpdateParams) => {
  return http.request("put", "/spChargeType/update", { data: params });
};

// 删除收费项目类别
export const deleteChargeType = (params: ChargeTypeDeleteParams) => {
  return http.request("delete", `/spChargeType/delete?id=${params.id}`);
};

// 获取所有收费项目类别（用于下拉选择）
export const getAllChargeTypes = () => {
  return http.request<{
    code: number;
    data: ChargeTypeItem[];
    message: string;
  }>("get", "/spChargeType/findAll");
};
